package com.qboot.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.date.DateUtil;
import com.qboot.common.annotation.Log;
import com.qboot.common.controller.BaseController;
import com.qboot.common.entity.Result;
import com.qboot.common.entity.TableResult;
import com.qboot.common.utils.EasyPoiExcelUtils;
import com.qboot.system.service.SysLoginLogService;
import com.qboot.system.vo.SysLoginLogVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 登录日志
 *
 * @author Tellsea
 * @date 2022-12-30
 */
@Api(tags = "登录日志")
@RestController
@RequestMapping("/system/sysLoginLog")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SysLoginLogController extends BaseController {

    private final SysLoginLogService sysLoginLogService;

    @ApiOperation("登录日志查询")
    @SaCheckPermission("system:sysLoginLog:list")
    @GetMapping("/list")
    public TableResult<SysLoginLogVo> queryList(SysLoginLogVo entity) {
        return TableResult.ok(sysLoginLogService.queryList(getPage(), entity));
    }

    @ApiOperation("登录日志根据主键查询")
    @Log("登录日志根据主键查询")
    @SaCheckPermission("system:sysLoginLog:get")
    @GetMapping("/queryById/{id}")
    public Result<SysLoginLogVo> queryById(@PathVariable("id") Long id) {
        return queryResult(sysLoginLogService.queryById(id));
    }

    @ApiOperation("登录日志导出")
    @Log("登录日志导出")
    @SaCheckPermission("system:sysLoginLog:export")
    @GetMapping("/exportExcel")
    public void exportExcel(SysLoginLogVo entity) {
        List<SysLoginLogVo> list = sysLoginLogService.queryList(getAllPage(), entity).getRecords();
        EasyPoiExcelUtils.exportExcel(list, "登录日志-" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss"), SysLoginLogVo.class);
    }

    @ApiOperation("登录日志根据主键删除")
    @Log("登录日志根据主键删除")
    @SaCheckPermission("system:sysLoginLog:remove")
    @GetMapping("/removeById/{id}")
    public Result removeById(@PathVariable("id") Long id) {
        return removeResult(sysLoginLogService.removeById(id));
    }

    @ApiOperation("登录日志根据主键批量删除")
    @Log("登录日志根据主键批量删除")
    @SaCheckPermission("system:sysLoginLog:removeBatch")
    @GetMapping("/removeBatchByIds/{ids}")
    public Result removeBatchByIds(@PathVariable("ids") List<Long> ids) {
        return removeResult(sysLoginLogService.removeBatchByIds(ids));
    }
}
